package com.zhang.first.day03;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;

/**
 * @title: ProcessFunction
 * @author: zhang
 * @date: 2022/1/16 15:22
 */
public class Example7 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        env
                .fromElements("white", "black", "gray")
                .process(new ProcessFunction<String, String>() {
                    @Override
                    public void processElement(String value, ProcessFunction<String, String>.Context ctx, Collector<String> out) throws Exception {
                        if (value.equals("white")) {
                            out.collect(value);
                        } else if (value.equals("black")) {
                            out.collect(value);
                            out.collect(value);
                        }
                    }
                })
                .print();

        env.execute();
    }
}
